home *** CD-ROM | disk | FTP | other *** search
- /* AfterDark.c
-
- error=AfterDarkDisable();
- error=AfterDarkEnable();
-
- Disable and later re-enable the popular screen saver, AfterDark. An error code is
- returned if the relevant Gestalt selectors are not installed, i.e. no
- AfterDark-compatible screen saver is present.
-
- Written by David Brainard, based on documentation supplied by Berkeley Systems
- Mac Tech Support, brklysystm@aol.com. Ask them for the AfterDarkGestalt.h file.
-
- The interface to the screen saver is generic. Any screen saver that installs the
- same Gestalt selectors would be controlled by these two routines, but we haven't
- tested that.
-
- SEE ALSO:
- IsFileSharingOn.c
-
- HISTORY:
- 6/15/95 dhb Wrote it.
- 6/16/95 dhb Don't call procedure on PPC, as it causes a crash.
- 6/20/95 dhb Make it work on PPC, use symbol GENERATING68K.
- 6/21/95 dhb Conditional compiles so that it will still work on 68K.
- 6/23/95 dgp Removed the stuff that was MATLAB-specific. Renamed
- variables to make the code more self documenting.
- 6/23/95 dhb Added necessary stuff from AfterDarkGestalt.h.
- Include VideoToolbox.h.
- Move prototypes to VideoToolbox.h.
- */
-
- #include <VideoToolbox.h>
-
- // Gestalt called with 'SAVR' selector returns longword bitmask.
- #define gestaltScreenSaverAttr 'SAVR'
- enum {
- gestaltSaverTurnedOn = 0, /* saver enabled/disabled. */
- gestaltSaverAsleep, /* saver currently asleep. */
- gestaltSaverDemoMode, /* saver sleeping in demo mode. */
- gestaltSaverPasswordMode, /* saver sleeping in password-protected mode. */
- gestaltAppDrawingDisabled /* Quickdraw drawing disallowed between module animation frames. */
- };
-
- // Gestalt called with 'SAVC' selector returns a pointer
- // to a procedure. Pass the appropriate command
- #define gestaltScreenSaverControl 'SAVC'
- enum SaverCommand {
- gestaltSaverWakeUp,
- gestaltSaverSleep,
-
- /* defined in AD 2.0x and later */
- gestaltSaverOn,
- gestaltSaverOff,
-
- /* defined for AD 3.0 and later */
- gestaltSysIQOn,
- gestaltSysIQOff,
-
- gestaltForceShort = 257
- };
- typedef short SaverCommand;
- typedef pascal OSErr (*SaverControlProcPtr) (SaverCommand command);
-
- static OSErr AfterDarkCommand(SaverCommand command);
-
- #if !GENERATING68K
- enum {
- uppSaverProcInfo=kPascalStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
- | STACK_ROUTINE_PARAMETER(1,SIZE_CODE(sizeof(SaverCommand)))
- };
- #endif
-
-
- OSErr AfterDarkEnable(void)
- {
- return AfterDarkCommand(gestaltSaverOn);
- }
-
-
- OSErr AfterDarkDisable(void)
- {
- return AfterDarkCommand(gestaltSaverOff);
- }
-
- static OSErr AfterDarkCommand(SaverCommand command)
- {
- OSErr error;
- long response;
- SaverControlProcPtr saverProcPtr;
- #if !GENERATING68K
- UniversalProcPtr saverUPP=NULL;
- #endif
-
- // Make sure the screen saver is installed, return if not.
- error=Gestalt(gestaltScreenSaverAttr,&response);
- if(error)return error;
-
- // Get a pointer to the screen saver's control procedure
- error=Gestalt(gestaltScreenSaverControl,(long *)&saverProcPtr);
- if(error)return error;
-
- // Ask the control procedure to perform the command
- #if GENERATING68K
- error=(*saverProcPtr)(command);
- #else
- saverUPP=NewRoutineDescriptor((ProcPtr)saverProcPtr,uppSaverProcInfo,kM68kISA);
- if(saverUPP==NULL)return 1; // Memory allocation failed.
- error=(OSErr)CallUniversalProc(saverUPP,uppSaverProcInfo,command);
- DisposeRoutineDescriptor(saverUPP);
- #endif
- return error;
- }
-